package jdk.functionclass;

import jdk.entity.UserEntity;
import jdk.util.FunctionUtil;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
 * Predicate 函数式
 *
 * @author songyafei
 */
public class PredicateTest1 {


    public static void main(String[] args) {

        List<UserEntity> userEntityList = new ArrayList<>();

        userEntityList.add(new UserEntity(1L, 12, "王博", LocalDate.now().minusYears(2)));
        userEntityList.add(new UserEntity(2L, 20, "李博", LocalDate.now().minusYears(3)));
        userEntityList.add(new UserEntity(3L, 17, "熊博", LocalDate.now().minusYears(6)));
        userEntityList.add(new UserEntity(4L, 23, "张博", LocalDate.now().minusYears(1)));
        userEntityList.add(new UserEntity(5L, 38, "肖博", LocalDate.now().minusYears(22)));

        //用filter 也可以实现该效果
        List<UserEntity> userEntities = FunctionUtil.filterList(userEntityList, (UserEntity us) -> us.getAge() > 18 && us.getUserId() > 1);
        userEntities.forEach(System.out::println);

        FunctionUtil.getT(Arrays.asList(1,2,3,4,5,6,7),(Integer s) -> System.out.print(s));
        FunctionUtil.getT(userEntityList,(UserEntity u)-> System.out.println(u.getAge()));
        FunctionUtil.getT(userEntityList,(UserEntity u)-> System.out.println(u.getCreatedDate()));
        FunctionUtil.getT(userEntityList,(UserEntity u)-> System.out.println(u.getName()));
    }


}
